package com.apes.fico.masterdata.gl.model;

import com.alibaba.fastjson.annotation.JSONField;
import com.apes.framework.jpa.ApesBean;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Name;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.util.DateUtil;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.util.Date;

@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = AccountingPeriodItem.CONST_TABLE_NAME, indexes = {
        @Index(columnList = "period_name,acc_period_id", unique = true)
})
public class AccountingPeriodItem implements ApesBean {
    public final static String CONST_TABLE_NAME = "mas_acc_period_item";

    @Id
    @Column(name = "id", length = 8)
    @ApesGenerator(code = CONST_TABLE_NAME, name = "会计月份期间明细")
    @Comment("编号")
    private String id;

    @NotNull
    @Column
    @Comment("期间数量")
    private Integer period_num;

    @Column
    @Name
    @Comment("期间名称")
    private String period_name;


    @Column
    @JSONField(format = DateUtil.SHOW_DATE_FORMAT)
    @Temporal(TemporalType.DATE)
    private Date fromDate;

    @Column
    @JSONField(format = DateUtil.SHOW_DATE_FORMAT)
    @Temporal(TemporalType.DATE)
    private Date thruDate;

    @NotNull
    @ManyToOne(optional = false)
    @JoinColumn(name = "acc_period_id", referencedColumnName = "id")
    @Comment("会计期间档案主键")
    private AccountingPeriod accountingPeriod;

    @NotNull
    @Column(name = "year_month")
    @Comment("年月")
    private int yearMonth;

    @NotNull
    @Column(name = "month")
    @Comment("月")
    private int month;

    @Column(name = "carry_over_pl_flag", nullable = false, columnDefinition = "number(1,0) default 0")
    @Comment("损益结转标记") //0:否 1：是
    private boolean carryOverPLFlag = false;

    @Column(name = "monthly_flag", nullable = false, columnDefinition = "number(1,0) default 0")
    @Comment("月结标记") //0:否 1：是
    private boolean monthlyFlag = false;
}
